package scheduler;

import java.text.ParseException;
import java.util.LinkedList;
import java.util.ListIterator;

public class User {
	String userId;
	String userName;
	String UserPassword;
	LinkedList<Job> jobs = new LinkedList<Job>();
	
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getUserPassword() {
		return UserPassword;
	}
	public void setUserPassword(String userPassword) {
		UserPassword = userPassword;
	}
	
	public String encryptPassword(String nonEncryptedPassword) {
		return "*" + nonEncryptedPassword + "*";
	}
	
	public String dencryptPassword(String encryptedPassword) {
		int len = encryptedPassword.length();
		
		return encryptedPassword.substring(1, len-1);
	}
	
	public User retrUser(String userId) throws ParseException {
		User u = new User();
		Job newJob;
		if (userId == "Oweson") {
			u.setUserId(userId);
			u.setUserName("Oweson Flynn");
			u.setUserPassword("*secret*");

			// Add Job 1
			newJob = new Job();
			newJob.buildJob(1);
			u.jobs.add(newJob);

			// Add job 3
			newJob = new Job();
			newJob.buildJob(3);
			u.jobs.add(newJob);

		} else if (userId == "John") {
			this.setUserId(userId);
			u.setUserName("John Smith");
			u.setUserPassword("*secret*");

			// Add Job 2
			newJob = new Job();
			newJob.buildJob(2);
			u.jobs.add(newJob);
		}
		return u;
	}

	// Retrieve from persistent store
	public void buildUser(String userId) throws ParseException {
		Job newJob;
		
		
		if (userId == "Oweson") {
				this.setUserId(userId);
				this.setUserName("Oweson Flynn");
				this.setUserPassword("*secret*");
				
				// Add Job 1
				newJob = new Job();
				newJob.buildJob(1);
				this.jobs.add(newJob);
				
				// Add job 3
				newJob = new Job();
				newJob.buildJob(3);
				this.jobs.add(newJob);
				
		} else if (userId == "John") {
			this.setUserId(userId);
				this.setUserName("John Smith");
				this.setUserPassword("*secret*");
				
				// Add Job 2
				newJob = new Job();
				newJob.buildJob(2);
				this.jobs.add(newJob);
		}
	}

	
	public void print() {
		Job theJob;
		System.out.println( "*** Start of User ***");
		System.out.println("\tUserId:        " + this.userId );
		System.out.println("\tUser Name:     " + this.userName );
		System.out.println("\tUserPassword: [" + this.UserPassword + "]");
		ListIterator itr = this.jobs.listIterator();
		while(itr.hasNext())
		{
			theJob = (Job)itr.next(); 
			theJob.print();
		}
		System.out.println( "*** End of User ***\n");

	}
}
